package com.jusha.formulacalculation.functions;

import com.jusha.formulacalculation.Result;
import com.jusha.formulacalculation.exception.FunctionParamException;
import com.jusha.formulacalculation.interfaces.IProcessFunction;

/**
 * 函数包装类
 */
public class PackFunction implements IProcessFunction {
    private IProcessFunction processFunction;

    public int getParamsCount() {
        return paramsCount;
    }

    private int paramsCount;

    public PackFunction(int paramsCount, IProcessFunction processFunction) {
        this.paramsCount = paramsCount;
        this.processFunction = processFunction;
    }

    @Override
    public Result execute(double... args) throws FunctionParamException {
        if (args.length != paramsCount)
            return Result.wrongParamCount();
        return processFunction.execute(args);
    }
}
